package cn.mysdp.utils;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName:
 * @Description:
 * @Author: SDP
 * @Date: 2020-10-30
 * Table:
 * Comment:
 */
@Getter
@Setter
public class SplitUtil {
    public static String[] split(String str, String v) {
        String[] strs = str.split(v);
        if (strs.length == 0) {
            return new String[]{""};
        }
        return strs;
    }

    public static List<String> splitLines(String str) {
        String[] lines = SplitUtil.split(str, "\n\r");
        List<String> destLines = new ArrayList<>();
        for(String line: lines) {
            String[] subLinesByLn = SplitUtil.split(line,"\n");
            for(String subLineByLn: subLinesByLn) {
                String[] subLinesByLr = SplitUtil.split(subLineByLn, "\r");
                for(String subLineByLr: subLinesByLr) {
                    destLines.add(subLineByLr);
                }
            }
        }
        return destLines;
    }

}
